#ifndef DHT11_H
#define DHT11_H

#include "DHT.h"
#include <Wire.h>

#define DHTPIN 15
#define DHTTYPE DHT11

float humidity;
float temperature;

DHT dht(DHTPIN, DHTTYPE);

long previousMillis_dht11;
const int interval_dht11 = 1000;

void setup_dht11()
{
  dht.begin();
  previousMillis_dht11 = 0;
}

void dht11_on()
{
  humidity = dht.readHumidity() + 20.0;
  temperature = dht.readTemperature() - 1;

  Serial.print(F("Humidity: "));
  Serial.print(humidity);
  Serial.print(F("%  Temperature: "));
  Serial.print(temperature);
  Serial.print(F("°C "));

  // Check if any reads failed and exit early (to try again).
  if (isnan(humidity) || isnan(temperature))
  {
    Serial.println(F("Failed to read from DHT sensor!"));
    humidity = 10.0;
    temperature = 10.0;
    return;
  }
}

void loop_dht11()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis_dht11 >= interval_dht11)
  {
    previousMillis_dht11 = currentMillis; // Remember the time
    dht11_on();
  };
}

#endif /* DHT11_H */
